import {getCurrentPath} from '@/utils/uni-api-wrap/route'
import {queryString} from '@/utils/utils'

const getShareData = (query = {}) => {
  let qs = queryString(query)
  if (qs) qs = `?${qs}`
  const path = `/${getCurrentPath() || 'pages/index/index'}${qs}`
  return {
    title: import.meta.env.VITE_APP_TITLE,
    imageUrl: 'https://mini-gdeia.oss-cn-guangzhou.aliyuncs.com/2024/132/2226566f0571aac484a7b3ce8ce0dbc20605069462.png',
    path
  }
}

export default {
  data () {
    return {
      shareMixinData: {
        query: {}
      }
    }
  },
  onLoad (query) {
    this.shareMixinData.query = query
  },
  onShareAppMessage() {
    return getShareData(this.shareMixinData.query)
  },
  onShareTimeline() {
    return getShareData(this.shareMixinData.query)
  }
}
